from pathlib import Path
from pydantic import BaseModel
from pydantic_settings import BaseSettings, SettingsConfigDict


BASE_DIR = Path(__file__).parent.parent.parent
DB_NAME = "scan.db"
DB_PATH = BASE_DIR / DB_NAME


class AuthJWT(BaseModel):
    private_key_path: Path = BASE_DIR / "serts" / "jwt-private.pem"
    public_key_path: Path = BASE_DIR / "serts" / "jwt-public.pem"
    algorithm: str = "RS256"
    access_token_expire_minutes: int = 60 * 24 * 7


class DbSettings(BaseModel):
    db_name: str = DB_NAME
    url: str = f"sqlite+aiosqlite:///{DB_PATH}"
    sync_url: str = f"sqlite:///{DB_PATH}"
    echo: bool = True
    url_for_bot: str = "sqlite+aiosqlite:///{}"


class Settings(BaseSettings):
    debug: bool
    project_name: str
    version: str
    debug: bool
    cors_allowed_origins: str
    api_v1_prefix: str
    celery_broker_url: str
    celery_result_backend: str
    tg_bot_token: str
    tg_bot_username: str
    tg_bot_name: str

    model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")

    auth_jwt: AuthJWT = AuthJWT()
    db: DbSettings = DbSettings()


settings = Settings()  # type: ignore
